package us.icitap.commandcenter.ui.shared;

import java.util.List;
import com.vaadin.data.util.BeanItemContainer;

import us.icitap.commandcenter.business.ejb.persistence.Call;
import us.icitap.commandcenter.ui.custom.CustTable;

public class CallTable extends CustTable{

	final BeanItemContainer<Call> beans  = new BeanItemContainer<Call>(Call.class);
	
	private String baseCaption;
	
	
	
	public CallTable() {
		super();
		this.setContainerDataSource(beans);
	}


	public CallTable(String caption) {
		super(caption);
		baseCaption = caption;
		this.setContainerDataSource(beans);
	}

	
	public void addCallList(List<Call> callList){
		beans.addAll(callList);
		this.updateTable();
	}
	
	
	public void updateTable(){
		boolean[] order = {true,false};
		this.sort(new Object[]{"actualStatus", "recordDate"}, order);
		this.setCaption(this.baseCaption + beans.size());
		
	}
	
	public void updateCall(Call call){
		beans.removeItem(call);
		beans.addBean(call);
		this.updateTable();
	}


	public void addCall(Call call){
		beans.addBean(call);
		this.updateCall(call);
	}
	
	public void removeCall(Call call){
		beans.removeItem(call);
		
	}
	
	
}
